package com.yuehuanghun.framework.util;

import java.text.DecimalFormat;
import java.util.concurrent.ConcurrentHashMap;

public class DecimalFormatterRepo {

	private static final ConcurrentHashMap<String, DecimalFormat> repo = new ConcurrentHashMap<String, DecimalFormat>();
	
	public static final DecimalFormat getFormatter(String pattern) {
		if(pattern == null) {
			throw new IllegalArgumentException("pattern不能为空");
		}
		
		DecimalFormat decimalFormat = repo.get(pattern);
		if(decimalFormat == null) {
			decimalFormat = new DecimalFormat(pattern);
			repo.putIfAbsent(pattern, decimalFormat);
		}
		return decimalFormat;
	}
}
